package com.example.springtest;


import cn.hutool.core.io.IoUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@RestController
public class controller {
    @RequestMapping("/list")
    public List<user> responseList() throws Exception{
        FileInputStream file=new FileInputStream("SpringTest/src/main/resources/static/user.txt");
        ArrayList<String> list = IoUtil.readUtf8Lines(file, new ArrayList<>());
        List<user> result=list.stream().map((line)->{
            String[] str=line.split(",");
            Integer id=Integer.parseInt(str[0]);
            String username=str[1];
            String password=str[2];
            String name=str[3];
            Integer age=Integer.parseInt(str[4]);
            String updateTime=str[5];
            return new user(id,username,password,name,age,updateTime);
        }).toList();
        return result;
    }
}